package controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Page;
import pojo.Vender;
import response.Result;
import service.VenderService;
import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName 刘星宇
 * @Description TODO
 * @date 2022/11/28 18:52
 * @Version 1.0
 */
@RestController
public class VenderController {
    @Resource
    private VenderService venderService;
    @RequestMapping("getVender")
    public Result getVender(Integer currentPage, Integer pageSize, String venderCode, String name){
       Page<Vender> page = new Page<Vender>();
       page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        Vender vender = new Vender();
        vender.setVenderCode(venderCode);
        vender.setName(name);
        int totalRecord = venderService.getCount(page, vender);
        List<Vender> list = venderService.venderAllByPage(page,vender);
        page.setLists(list);
        page.setTotalRecord(totalRecord);
        return Result.ok(page);
    }
    //新增
    @RequestMapping("venderAdd")
    public int venderAdd(@RequestBody Vender vender){
        int i = venderService.AddVender(vender);
        return i;
    }
    //修改
    @RequestMapping("venderUpd")
    public int venderUpd(@RequestBody Vender vender){
        int i = venderService.UpdateVender(vender);
        return i;
    }
    //删除
    @RequestMapping("venderDel")
    public int venderDel(String venderCode){
        int i = venderService.DelVender(venderCode);
        return i;
    }
}
